using UnityEngine;

[RequireComponent(typeof(CircleCollider2D), typeof(SpriteRenderer))]
public class Collectible : MonoBehaviour
{
	private Collider2D cCollider;

	private SpriteRenderer cSprite;

	private Rigidbody2D cRigidbody;

	private WaitForEndOfFrame wfef;

	private Color color;

	private Vector3 initialScale;

	private Vector3 initPos;

	private bool isAlive;

	private int mass;

	private Vector3 one = Vector3.one;

	public Rigidbody2D CRigidbody
	{
		get
		{
			return cRigidbody;
		}
	}

	public Vector2 Velocity
	{
		get
		{
			return cRigidbody.velocity;
		}
		set
		{
			cRigidbody.velocity = value;
		}
	}

	public Vector2 Position
	{
		get
		{
			return cRigidbody.position;
		}
	}

	public Color Color
	{
		get
		{
			return color;
		}
	}

	public bool IsAlive
	{
		get
		{
			return isAlive;
		}
	}

	public int Mass
	{
		get
		{
			return mass;
		}
	}

	public virtual void Awake()
	{
		cCollider = GetComponent<Collider2D>();
		cSprite = GetComponent<SpriteRenderer>();
		cRigidbody = GetComponent<Rigidbody2D>();
		initialScale = one / 2f;
		wfef = new WaitForEndOfFrame();
	}

	public virtual void Initialize(int size, int mass, Color color)
	{
		isAlive = true;
		cSprite.color = (this.color = color);
		this.mass = mass;
		base.transform.localScale = initialScale + one * size * 0.11f;
		initPos = GameManager.GetRandomPosition(1f);
		EnablePhysics();
	}

	public void SetPosition()
	{
		cRigidbody.position = initPos;
	}

	public virtual void InitializeWithMove(int size, int mass, Color color, Vector3 start, Vector2 force)
	{
		isAlive = true;
		cSprite.color = (this.color = color);
		this.mass = mass;
		base.transform.localScale = initialScale + one * size * 0.2f;
		initPos = start;
		cRigidbody.velocity = Vector2.zero;
		EnablePhysics();
		cRigidbody.AddForce(force);
	}

	~Collectible()
	{
		isAlive = false;
		DisablePhysics();
		CollectiblePool.Instance.ReturnCollectible(this);
	}
	public void FinalizeCollectible()
	{
		isAlive = false;
		DisablePhysics();
		CollectiblePool.Instance.ReturnCollectible(this);
	}
	public void EnablePhysics()
	{
		cCollider.enabled = true;
		cRigidbody.simulated = true;
	}

	public void DisablePhysics()
	{
		cRigidbody.velocity = Vector2.zero;
		cCollider.enabled = false;
		cRigidbody.simulated = false;
	}
}
